package com.sky.controller.user;

import com.sky.result.Result;
import com.sky.service.VoucherOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: invictusQAQ
 * @Date: 2023-09-06-17:16
 * @Description: 用户代金券相关接口
 */
@RestController
@Slf4j
@RequestMapping("/user/voucher")
@Api(tags = "用户代金券相关接口")
public class VoucherOrderController {

    @Autowired
    private VoucherOrderService voucherOrderService;

    /**
     * 秒杀券下单
     * @param voucherId
     * @return Result<Long>
     **/
    @ApiOperation("秒杀券下单")
    @PostMapping("/submit")
    public Result submit(@RequestParam("id") Long voucherId){
        Long orderId=voucherOrderService.submitOrder(voucherId);
        if(orderId==1||orderId==2){
            return Result.error(orderId==1?"秒杀券已售罄" : "不允许重复下单");
        }else{
            return Result.success(orderId);
        }
    }
}
